package com.hankol.newretail.adapter

import android.widget.TextView
import com.baselibrary.extension.setMallPriceTTF
import com.baselibrary.utils.AmountUtil
import com.baselibrary.utils.GlideUtils
import com.baselibrary.utils.SpecUtils
import com.baselibrary.view.RoundCornerImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.newretail.R
import com.hankol.newretail.bean.AfterSaleListBean

/**
 * @author: 关忆北、
 * @date: 2022/8/10
 * @Des：
 */
class AfterSalesAdapter : BaseQuickAdapter<AfterSaleListBean, BaseViewHolder>(R.layout.item_after_sales) {
    override fun convert(helper: BaseViewHolder, item: AfterSaleListBean) {
        val ivAfterSalesCover = helper.getView<RoundCornerImageView>(R.id.iv_after_sales_cover)
        helper.setText(R.id.tv_price, AmountUtil.changeF2YKeepTwo("${item.products[0].afterSaleRequestPrice}"))
        helper.getView<TextView>(R.id.tv_price).setMallPriceTTF(mContext)
        helper.getView<TextView>(R.id.tv_unit).setMallPriceTTF(mContext)
        helper.addOnClickListener(R.id.tv_after_sales_revoke)
        helper.setText(R.id.tv_after_sales_order_number, "售后服务单 ${item.afterSaleCode}").setText(R.id.tv_after_sales_order_state, getAfterSalesState(item.afterSaleStatus)).setText(R.id.iv_after_sales_title, item.products[0].spuName).setText(R.id.tv_after_sales_norms, SpecUtils.getNormsStr(item.products[0].specList)).setText(R.id.tv_after_sales_quantity, "申请数量：${item.products[0].num}")
                .setGone(R.id.tv_after_sales_revoke, item.afterSaleStatus == 0)
                .setGone(R.id.v_bottom, item.afterSaleStatus == 0)
        GlideUtils.loadImg_101(mContext.applicationContext, item.products[0].skuCover, ivAfterSalesCover)
    }


    fun getAfterSalesState(afterSaleStatus: Int): String {
        when (afterSaleStatus) {
            0 -> {
                return "售后待处理"
            }
            1 -> {
                return "已同意"
            }
            2 -> {
                return "已拒绝"
            }
        }
        return "未知"
    }

}